package com.shenhaofeng.user;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;


/**
 * Created by Administrator on 2016/9/12.
 */
public class PropertyBundle {

    Map<String, Object> propertyMap = new HashMap<>();


    public PropertyBundle() {
    }


    public PropertyBundle(PropertyBundle propertyBundle) {
        propertyMap.putAll(propertyBundle.propertyMap);
    }

    public Set<String> keySet(){
        return propertyMap.keySet();
    }




    public void clear() {
        propertyMap.clear();
        ;
    }


    public void remove(String key) {
        propertyMap.remove(key);
    }


    public void putString(String key, String value) {
        propertyMap.put(key, value);
    }


    public void putInt(String key, int value) {
        propertyMap.put(key, value);
    }


    public void putFloat(String key, float value) {
        propertyMap.put(key, value);
    }


    public void putBoolean(String key, boolean value) {
        propertyMap.put(key, value);
    }


    public void putLong(String key, long value) {
        propertyMap.put(key, value);
    }


    public void putStringSet(String key, Set<String> value) {
        propertyMap.put(key, value);
    }


    public Object get(String key){
        return propertyMap.get(key);
    }

    public String getString(String key) {
        Object value = propertyMap.get(key);
        if (value == null) {
            return null;
        }
        if (String.class.isInstance(key)) {
            return String.class.cast(value);
        } else {
            return null;
        }
    }


    public String getString(String key, String defaultValue) {
        String value = getString(key);
        return value == null ? defaultValue : value;
    }


    public int getInt(String key, int defaultValue) {
        Object value = propertyMap.get(key);
        if (value == null) {
            return defaultValue;
        }
        if (Integer.class.isInstance(key)) {
            return Integer.class.cast(value);
        } else {
            return defaultValue;
        }
    }


    public float getFloat(String key, float defaultValue) {
        Object value = propertyMap.get(key);
        if (value == null) {
            return defaultValue;
        }
        if (Float.class.isInstance(key)) {
            return Float.class.cast(value);
        } else {
            return defaultValue;
        }
    }


    public float getLong(String key, long defaultValue) {
        Object value = propertyMap.get(key);
        if (value == null) {
            return defaultValue;
        }
        if (Long.class.isInstance(key)) {
            return Long.class.cast(value);
        } else {
            return defaultValue;
        }
    }


    public boolean getBoolean(String key, boolean defaultValue) {
        Object value = propertyMap.get(key);
        if (value == null) {
            return defaultValue;
        }
        if (Boolean.class.isInstance(key)) {
            return Boolean.class.cast(value);
        } else {
            return defaultValue;
        }
    }


    public Set<String> getStringSet(String key, Set<String> defaultValue) {
        Object value = propertyMap.get(key);
        if (value == null) {
            return defaultValue;
        }
        if (Set.class.isInstance(key)) {
            return Set.class.cast(value);
        } else {
            return defaultValue;
        }
    }

}
